<template>
	<view>
		<!-- 搜索组件 -->
		<view class="search-box">
			<u-search placeholder="请输入关键词" border-color="#E1027B" :show-action="false"></u-search>
		</view>
		<view class="scroll-view-container">
			<!-- 左侧滚动区域 -->
			<scroll-view class="left-scroll-view" scroll-y="true" :style="{ height: wh + 'px' }">

				<block v-for="(item,i) in cateList" :key="i">
					<view :class="['left-scroll-view-item', i === active ? 'active' : '']" @click="activechange(i)">
						{{item.cat_name}}
					</view>
				</block>
			</scroll-view>
			<!-- 右侧滚动条区域 -->
			<scroll-view class="right-scroll-view" scroll-y="true" :style="{ height: wh + 'px' }"
				:scroll-top="scrollTap">
				<view class="cateLevel2" v-for="(item2,i2) in cateLevel2" :key="i2">
					<!-- 二级分类标题 -->
					<view class="cateLevel2-title">
						/{{item2.cat_name}}/
					</view>
					<!-- 三级内容列表区域 -->
					<view class="catelevel3-list">
						<!-- 三级item项 -->
						<view class="catelevel3-item" v-for="(item3,i3) in item2.children" :key="i3"
							@click="shoplist(item3)">
							<!-- 图片区域 -->
							<image :src="item3.cat_icon" ></image>
							<!-- 名称区域 -->
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		cateList
	} from "@/util/cateList.js"
	export default {
		data() {
			return {
				// 窗口的可用高度 = 屏幕高度 - navigationBar高度 - tabBar 高度
				wh: 0,
				cateList: cateList,
				cateLevel2: cateList,
				active: 0,
				scrollTap: 0
			}
		},
		onLoad() {
			//获取当前系统的相关信息
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight
			console.log(cateList)
			this.cateLevel2 = this.cateList[0].children
		},
		methods: {
			activechange(i) {
				this.active = i
				//二级标题重新赋值
				this.cateLevel2 = this.cateList[i].children
				//判断是否重置回到二级标题（设置1和0）
				this.scrollTap = this.scrollTap === 0 ? 1 : 0
			},
			shoplist(item) {
				uni.navigateTo({
					url: "../details/details"

				})

			},
			gotoSearch() {
				uni.navigateTo({
					url: "../search/search"
				})
			}

		}
	}
</script>

<style lang="scss">
	.search-box {
		background: #E1027B;
		padding: 5px;
		position: sticky;
		top: 0;
		z-index: 2;
	}
	.scroll-view-container {
		display: flex;

		.left-scroll-view {
			width: 120px;

			.left-scroll-view-item {
				line-height: 120rpx;
				background: #F7F7F7;
				text-align: center;
				font-size: 12px;

				&.active {
					background: #FFFFFF;
					position: relative;

					&::before {
						content: '';
						display: block;
						position: absolute;
						background: #c00000;
						width: 3px;
						height: 30px;
						top: 50%;
						left: 0;
						transform: translateY(-50%);

					}
				}
			}
		}
	}

	.cateLevel2-title {
		font-size: 12px;
		font-weight: bold;
		text-align: center;
		padding: 15px 0;
	}

	.catelevel3-list {
		display: flex;
		flex-wrap: wrap;

		.catelevel3-item {
			width: 33.33%;
			display: flex;
			justify-content: center;
			align-items: center;
			// margin-bottom: 20rpx;
			flex-direction: column;

			image {
				width: 60px;
				height: 60px;
				margin-bottom: 25rpx;
			}

			text {
				font-size: 12px;
			}
		}
	}


</style>
